import '../scss/index.scss';
import Vue from 'vue/dist/vue.esm.js';
import axios from 'axios';
import BScroll from 'better-scroll';
import '../fonts/iconfont.css';
let vm = new Vue({
    el:'#app',
    data:{
        list:[],
        scroll:null,
        up:"上拉加载",
        limit:10,
        pagenum:1
    },
    created(){
        this.getData();
        this.$nextTick().then(() => {
            console.log(this.$refs.header.innerHTML)
        })
    },
    methods:{
        getData(){
            axios.get('/api/list').then((res) => {
                console.log(res);
                if(res.data.code === 1){
                    this.list = this.list.concat(res.data.data);
                }
            }).catch((error) => {
                console.log(error)
            })
        }
    },
    mounted(){
        this.$nextTick(() => {
            this.scroll = new BScroll('.con',{
                probeType:2
            });
            let that = this;
            this.scroll.on('scroll',function(){
                if(this.y < this.maxScrollY - 44){
                    that.up = '释放加载更多'
                }else if(this.y < this.maxScrollY - 22){
                    that.up = '上拉加载'
                }
            })

            this.scroll.on('touchEnd',function(){
                if(that.up === '释放加载更多'){
                    that.getData();
                    that.up = '上拉加载'
                }
            })
        })
    },
    // updated(){
    //     // this.$nextTick(() => {
    //     //     this.scroll.refresh();
    //     // })
    // }
    watch:{
        list(){
            this.$nextTick(() => {
                this.scroll.refresh();
            })
        }
    }
})
